package demo.practice.leetcode;


import java.util.ArrayList;
import java.util.List;

class Node {
    public int val;
    public List<Node> children;

    public Node() {
    }

    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, List<Node> _children) {
        val = _val;
        children = _children;
    }
};


public class P580 {
    public static void main(String[] args) {

    }

//    public List<Integer> preorder(Node root) {
//        return  preorder(root,new ArrayList<Integer>());
//    }

    List<Integer> list = new ArrayList<Integer>();

    public List<Integer> preorder(Node root) {
        preorderPop(root);
        return list;
    }

    public void preorderPop(Node root) {
        if(root==null)
            return;
        list.add(root.val);
        root.children.forEach(e ->{ preorderPop(e); });
    }


}
